/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mop.dinnerbook.dao;

import com.mop.dinnerbook.bean.Project;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 *项目组操作业务类
 * @author Administrator
 */
public class ProjectDAO extends BaseDAO{
    /*
     获取所有的项目组
     */
    public List getAllProject(){
        List result = null;
        String sql="select pid,pname,remark from project order by pid";
        try {
			result = executeSelectList(sql, new Processor(){
				public Object product(ResultSet rst) throws SQLException{
					Project project = new Project();
					project.setPid(rst.getInt(1));
					project.setPname(rst.getString(2)); 
					project.setRemark(rst.getString(3));
					return project;
				}
			});
		} catch (SQLException e) {
                        System.out.println(sql);
			e.printStackTrace();
		}
        return result;
    }
    
    /*
     获取特定的项目组
     */
    public Project getProject(int pid){
        Project result = null;
        String sql="select pid,pname,remark from project where pid = " + pid;
        try {
			result = (Project)executeSelectObject(sql, new Processor(){
				public Object product(ResultSet rst) throws SQLException{
					Project project = new Project();
					project.setPid(rst.getInt(1));
					project.setPname(rst.getString(2));
					project.setRemark(rst.getString(3));
					return project;
				}
			});
		} catch (SQLException e) {
                        System.out.println(sql);
			e.printStackTrace();
		}
        return result;
    }
    /*
     获取特定项目组的订餐成员数量
     * 
     */
    public int getBookedMemberSize(int pid){
        Integer result = 0;
        String sql="select count(1) total from member a ,record b where b.rdate>=curdate() and a.valid = 1 and b.mid = a.mid and b.checked = 1 and a.pid = " + pid;
        try {
			result = (Integer)executeSelectObject(sql, new Processor(){
				public Object product(ResultSet rst) throws SQLException{
					int total  = rst.getInt(1);
					return total;
				}
			});
		} catch (SQLException e) {
                        System.out.println(sql);
			e.printStackTrace();
		}
        if(result == null) result = 0;
        return result;
    }
    /*
     获取特定项目组的所有成员数量
     */
    public int getAllMemberSize(){
        Integer result = null;
        String sql="select count(1) total from member where valid = 1";
        try {
                result = (Integer)executeSelectObject(sql, new Processor(){
                        public Object product(ResultSet rst) throws SQLException{
                                int total  = rst.getInt(1);
                                return total;
                        }
                });
	} catch (SQLException e) {
                System.out.println(sql);
		e.printStackTrace();
	}
        if(result == null) result = 0;
        return result;
    }
    /*
     获取所有项目组的成员数量
     */
    public int getBookedMemberSize(){
        Integer result = 0;
        String sql="select count(1) total from member a ,record b where b.rdate >=curdate() and a.valid = 1 and b.mid = a.mid and b.checked = 1";
        try {
			result = (Integer)executeSelectObject(sql, new Processor(){
				public Object product(ResultSet rst) throws SQLException{
					int total  = rst.getInt(1);
					return total;
				}
			});
		} catch (SQLException e) {
                        System.out.println(sql);
			e.printStackTrace();
		}
        if(result == null) result = 0;
        return result;
    }
    /*
     获取特定项目组的所有成员数量
     */
    public int getAllMemberSize(int pid){
        Integer result = 0;
        String sql="select count(1) total from member where valid = 1 and  pid = " + pid;
        try {
			result = (Integer)executeSelectObject(sql, new Processor(){
				public Object product(ResultSet rst) throws SQLException{
					int total  = rst.getInt(1);
					return total;
				}
			});
		} catch (SQLException e) {
                        System.out.println(sql);
			e.printStackTrace();
		}
        if(result == null) result = 0;
        return result;
    }
    
    
}
